// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyBoxAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyBoxAttributes
//
// Purpose:
//   This class contains attributes for the box operator.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a BoxAttributes.
//
struct BoxAttributesObject
{
    PyObject_HEAD
    BoxAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewBoxAttributes(int);
std::string
PyBoxAttributes_ToString(const BoxAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    const char *amount_names = "Some, All";
    switch (atts->GetAmount())
    {
      case BoxAttributes::Some:
          snprintf(tmpStr, 1000, "%samount = %sSome  # %s\n", prefix, prefix, amount_names);
          str += tmpStr;
          break;
      case BoxAttributes::All:
          snprintf(tmpStr, 1000, "%samount = %sAll  # %s\n", prefix, prefix, amount_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%sminx = %g\n", prefix, atts->GetMinx());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smaxx = %g\n", prefix, atts->GetMaxx());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sminy = %g\n", prefix, atts->GetMiny());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smaxy = %g\n", prefix, atts->GetMaxy());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sminz = %g\n", prefix, atts->GetMinz());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smaxz = %g\n", prefix, atts->GetMaxz());
    str += tmpStr;
    if(atts->GetInverse())
        snprintf(tmpStr, 1000, "%sinverse = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sinverse = 0\n", prefix);
    str += tmpStr;
    return str;
}

static PyObject *
BoxAttributes_Notify(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
BoxAttributes_SetAmount(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid amount value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Some";
        ss << ", All";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the amount in the object.
    obj->data->SetAmount(BoxAttributes::Amount(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
BoxAttributes_GetAmount(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetAmount()));
    return retval;
}

/*static*/ PyObject *
BoxAttributes_SetMinx(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the minx in the object.
    obj->data->SetMinx(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
BoxAttributes_GetMinx(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMinx());
    return retval;
}

/*static*/ PyObject *
BoxAttributes_SetMaxx(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the maxx in the object.
    obj->data->SetMaxx(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
BoxAttributes_GetMaxx(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMaxx());
    return retval;
}

/*static*/ PyObject *
BoxAttributes_SetMiny(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the miny in the object.
    obj->data->SetMiny(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
BoxAttributes_GetMiny(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMiny());
    return retval;
}

/*static*/ PyObject *
BoxAttributes_SetMaxy(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the maxy in the object.
    obj->data->SetMaxy(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
BoxAttributes_GetMaxy(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMaxy());
    return retval;
}

/*static*/ PyObject *
BoxAttributes_SetMinz(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the minz in the object.
    obj->data->SetMinz(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
BoxAttributes_GetMinz(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMinz());
    return retval;
}

/*static*/ PyObject *
BoxAttributes_SetMaxz(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the maxz in the object.
    obj->data->SetMaxz(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
BoxAttributes_GetMaxz(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMaxz());
    return retval;
}

/*static*/ PyObject *
BoxAttributes_SetInverse(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the inverse in the object.
    obj->data->SetInverse(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
BoxAttributes_GetInverse(PyObject *self, PyObject *args)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetInverse()?1L:0L);
    return retval;
}



PyMethodDef PyBoxAttributes_methods[BOXATTRIBUTES_NMETH] = {
    {"Notify", BoxAttributes_Notify, METH_VARARGS},
    {"SetAmount", BoxAttributes_SetAmount, METH_VARARGS},
    {"GetAmount", BoxAttributes_GetAmount, METH_VARARGS},
    {"SetMinx", BoxAttributes_SetMinx, METH_VARARGS},
    {"GetMinx", BoxAttributes_GetMinx, METH_VARARGS},
    {"SetMaxx", BoxAttributes_SetMaxx, METH_VARARGS},
    {"GetMaxx", BoxAttributes_GetMaxx, METH_VARARGS},
    {"SetMiny", BoxAttributes_SetMiny, METH_VARARGS},
    {"GetMiny", BoxAttributes_GetMiny, METH_VARARGS},
    {"SetMaxy", BoxAttributes_SetMaxy, METH_VARARGS},
    {"GetMaxy", BoxAttributes_GetMaxy, METH_VARARGS},
    {"SetMinz", BoxAttributes_SetMinz, METH_VARARGS},
    {"GetMinz", BoxAttributes_GetMinz, METH_VARARGS},
    {"SetMaxz", BoxAttributes_SetMaxz, METH_VARARGS},
    {"GetMaxz", BoxAttributes_GetMaxz, METH_VARARGS},
    {"SetInverse", BoxAttributes_SetInverse, METH_VARARGS},
    {"GetInverse", BoxAttributes_GetInverse, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
BoxAttributes_dealloc(PyObject *v)
{
   BoxAttributesObject *obj = (BoxAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *BoxAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyBoxAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "amount") == 0)
        return BoxAttributes_GetAmount(self, NULL);
    if(strcmp(name, "Some") == 0)
        return PyInt_FromLong(long(BoxAttributes::Some));
    if(strcmp(name, "All") == 0)
        return PyInt_FromLong(long(BoxAttributes::All));

    if(strcmp(name, "minx") == 0)
        return BoxAttributes_GetMinx(self, NULL);
    if(strcmp(name, "maxx") == 0)
        return BoxAttributes_GetMaxx(self, NULL);
    if(strcmp(name, "miny") == 0)
        return BoxAttributes_GetMiny(self, NULL);
    if(strcmp(name, "maxy") == 0)
        return BoxAttributes_GetMaxy(self, NULL);
    if(strcmp(name, "minz") == 0)
        return BoxAttributes_GetMinz(self, NULL);
    if(strcmp(name, "maxz") == 0)
        return BoxAttributes_GetMaxz(self, NULL);
    if(strcmp(name, "inverse") == 0)
        return BoxAttributes_GetInverse(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyBoxAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyBoxAttributes_methods[i].ml_name),
                PyString_FromString(PyBoxAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyBoxAttributes_methods, self, name);
}

int
PyBoxAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "amount") == 0)
        obj = BoxAttributes_SetAmount(self, args);
    else if(strcmp(name, "minx") == 0)
        obj = BoxAttributes_SetMinx(self, args);
    else if(strcmp(name, "maxx") == 0)
        obj = BoxAttributes_SetMaxx(self, args);
    else if(strcmp(name, "miny") == 0)
        obj = BoxAttributes_SetMiny(self, args);
    else if(strcmp(name, "maxy") == 0)
        obj = BoxAttributes_SetMaxy(self, args);
    else if(strcmp(name, "minz") == 0)
        obj = BoxAttributes_SetMinz(self, args);
    else if(strcmp(name, "maxz") == 0)
        obj = BoxAttributes_SetMaxz(self, args);
    else if(strcmp(name, "inverse") == 0)
        obj = BoxAttributes_SetInverse(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
BoxAttributes_print(PyObject *v, FILE *fp, int flags)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)v;
    fprintf(fp, "%s", PyBoxAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
BoxAttributes_str(PyObject *v)
{
    BoxAttributesObject *obj = (BoxAttributesObject *)v;
    return PyString_FromString(PyBoxAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *BoxAttributes_Purpose = "This class contains attributes for the box operator.";
#else
static char *BoxAttributes_Purpose = "This class contains attributes for the box operator.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(BoxAttributesType,         \
                  "BoxAttributes",           \
                  BoxAttributesObject,       \
                  BoxAttributes_dealloc,     \
                  BoxAttributes_print,       \
                  PyBoxAttributes_getattr,   \
                  PyBoxAttributes_setattr,   \
                  BoxAttributes_str,         \
                  BoxAttributes_Purpose,     \
                  BoxAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
BoxAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &BoxAttributesType
         || Py_TYPE(other) != &BoxAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    BoxAttributes *a = ((BoxAttributesObject *)self)->data;
    BoxAttributes *b = ((BoxAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static BoxAttributes *defaultAtts = 0;
static BoxAttributes *currentAtts = 0;

static PyObject *
NewBoxAttributes(int useCurrent)
{
    BoxAttributesObject *newObject;
    newObject = PyObject_NEW(BoxAttributesObject, &BoxAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new BoxAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new BoxAttributes(*defaultAtts);
    else
        newObject->data = new BoxAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapBoxAttributes(const BoxAttributes *attr)
{
    BoxAttributesObject *newObject;
    newObject = PyObject_NEW(BoxAttributesObject, &BoxAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (BoxAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
BoxAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewBoxAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef BoxAttributesMethods[] = {
    {"BoxAttributes", BoxAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *BoxAttributesObserver = 0;

std::string
PyBoxAttributes_GetLogString()
{
    std::string s("BoxAtts = BoxAttributes()\n");
    if(currentAtts != 0)
        s += PyBoxAttributes_ToString(currentAtts, "BoxAtts.", true);
    return s;
}

static void
PyBoxAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("BoxAtts = BoxAttributes()\n");
        s += PyBoxAttributes_ToString(currentAtts, "BoxAtts.", true);
        cb(s);
    }
}

void
PyBoxAttributes_StartUp(BoxAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyBoxAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(BoxAttributesObserver == 0)
    {
        BoxAttributesObserver = new ObserverToCallback(subj,
            PyBoxAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyBoxAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete BoxAttributesObserver;
    BoxAttributesObserver = 0;
}

PyMethodDef *
PyBoxAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return BoxAttributesMethods;
}

bool
PyBoxAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &BoxAttributesType);
}

BoxAttributes *
PyBoxAttributes_FromPyObject(PyObject *obj)
{
    BoxAttributesObject *obj2 = (BoxAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyBoxAttributes_New()
{
    return NewBoxAttributes(0);
}

PyObject *
PyBoxAttributes_Wrap(const BoxAttributes *attr)
{
    return WrapBoxAttributes(attr);
}

void
PyBoxAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    BoxAttributesObject *obj2 = (BoxAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyBoxAttributes_SetDefaults(const BoxAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new BoxAttributes(*atts);
}

